home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#50 (Nov 89)
/
XCMD Code
/
Listing 1 of XCMD Corner
next >
Wrap
Text File
|
1989-09-11
|
2KB
|
86 lines
/********************************/
/* File: Catalog.c */
/* */
/* Given the reference number of*/
/* a working directory or volume*/
/* return a list of all files & */
/* folders in that directory */
/* */
/* if a name is given, use it, */
/* otherwise, use the id passed */
/* ---------------------------- */
/********************************/
#include <MacTypes.h>
#include <OSUtil.h>
#include <MemoryMgr.h>
#include <FileMgr.h>
#include <ResourceMgr.h>
#include <pascal.h>
#include <string.h>
#include <hfs.h>
#include "HyperXCmd.h"
#include "HyperUtils.h"
#define nil 0L
extern GetCatalog();
pascal void main( paramPtr )
XCmdBlockPtr paramPtr;
{
Handle catalog;
Str31 str;
short dirID;
/*** intialize the output container ***/
catalog = NewHandle( 0L );
/*** convert the wdid to a usable form ***/
if( paramPtr->params[1] ){
HLock( paramPtr->params[1] );
ZeroToPas( paramPtr, *(paramPtr->params[1]), &str );
HUnlock( paramPtr->params[1] );
dirID = (short)StrToNum( paramPtr, &str );
/*** given the id of a directory, ***/
/*** return a catalog for that directory ***/
GetCatalog( dirID, catalog );
}
else if( paramPtr->params[0] ){
char path[256];
CInfoPBRec catPB;
WDPBRec wdPB;
HLock( paramPtr->params[0] );
ZeroToPas( paramPtr, *(paramPtr->params[0]), &path );
HUnlock( paramPtr->params[0] );
/*** get a directory id to this path ***/
catPB.dirInfo.ioNamePtr = (StringPtr)path;
catPB.dirInfo.ioFDirIndex = 0;
catPB.dirInfo.ioVRefNum = 0;
if( PBGetCatInfo( &catPB, 0 ) == noErr )
if( catPB.dirInfo.ioFlAttrib & 0x010 ){ /*** it's a directory ***/
wdPB.ioNamePtr = (StringPtr)path;
wdPB.ioWDProcID = 0;
if( PBOpenWD( &wdPB, 0 ) == noErr ){
wdPB.ioWDVRefNum= catPB.dirInfo.ioVRefNum;
wdPB.ioWDDirID = catPB.dirInfo.ioDrDirID;
GetCatalog( wdPB.ioVRefNum, catalog );
PBCloseWD( &wdPB, 0 );
}
}
}
/*** append a null to the end of the ***/
/*** the directory for Hypercard ***/
AppendCharToHandle( catalog, '\0' );
paramPtr->returnValue = catalog;
}